package com.tsinghua.server.mould;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsinghua.server.common.Result;
import com.tsinghua.server.mould.entity.*;
import com.tsinghua.server.mould.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: 模型管理
 * @author: Mr.Eric
 * @create: 2022/3/5 10:49
 */
@RestController
@RequestMapping(value = "/mould/")
public class MouldDataController {

    @Resource
    private FxjcCyzMoldingService cyzMoldingService;
    @Resource
    private FxjcCtzMoldingService ctzMoldingService;
    @Resource
    private FxjcYhMoldingService yhMoldingService;
    @Resource
    private FxjcBxMoldingService fxjcBxMoldingService;
    @Resource
    private FxjcZqMoldingService zqMoldingService;

    /**
     * 城投债分页
     * @param pageSize
     * @param pageNo
     * @param zwzt
     * @return
     */
    @GetMapping(value = "cyz/page")
    public Result cyzDataPage(
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(name = "zwzt", required = false) String zwzt
    ) {
        QueryWrapper<FxjcCyzMolding> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(zwzt)) {
            queryWrapper.like("zwzt", zwzt);
        }
        Page<FxjcCyzMolding> page = new Page<>(pageNo, pageSize);
        return Result.succ(cyzMoldingService.page(page, queryWrapper));
    }



    @GetMapping(value = "ctz/page")
    public Result ctzDataPage(
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(name = "zwzt", required = false) String zwzt
    ) {
        QueryWrapper<FxjcCtzMolding> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(zwzt)) {
            queryWrapper.like("zwzt", zwzt);
        }
        Page<FxjcCtzMolding> page = new Page<>(pageNo, pageSize);
        return Result.succ(ctzMoldingService.page(page, queryWrapper));
    }


    @GetMapping(value = "yh/page")
    public Result yhDataPage(
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(name = "zwzt", required = false) String zwzt
    ) {
        QueryWrapper<FxjcYhMolding> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(zwzt)) {
            queryWrapper.like("zwzt", zwzt);
        }
        Page<FxjcYhMolding> page = new Page<>(pageNo, pageSize);
        return Result.succ(yhMoldingService.page(page, queryWrapper));
    }

    @GetMapping(value = "bx/page")
    public Result bxDataPage(
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(name = "zwzt", required = false) String zwzt
    ) {
        QueryWrapper<FxjcBxMolding> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(zwzt)) {
            queryWrapper.like("zwzt", zwzt);
        }
        Page<FxjcBxMolding> page = new Page<>(pageNo, pageSize);
        return Result.succ(fxjcBxMoldingService.page(page, queryWrapper));
    }


    @GetMapping(value = "zq/page")
    public Result zqDataPage(
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize,
            @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
            @RequestParam(name = "zwzt", required = false) String zwzt
    ) {
        QueryWrapper<FxjcZqMolding> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(zwzt)) {
            queryWrapper.like("zwzt", zwzt);
        }
        Page<FxjcZqMolding> page = new Page<>(pageNo, pageSize);
        return Result.succ(zqMoldingService.page(page, queryWrapper));
    }



}
